/**
 * 第一次测试页面
 */

'use strict'
import {connect} from 'dva';
import React, {Component} from 'react';
import {CacheRoute} from "react-router-cache-route";
import {withRouter} from "react-router-dom";
import TuiJian from "./TuiJian";
import Full from "../../../components/layout/Full";
import TestQuiz from "../../../components/TestQuiz/TestQuiz";
import Welcome from "./Welcome";

@withRouter
class FirstTest extends Component {

  UNSAFE_componentWillMount() {
    //首次测试拉取题目,todo 周测后面这里加if else 拉取周测题目
    if (this.props.quizList.length === 0) this.props.dispatch({type: 'quiz/fetchTimus', body: {tmSource: {type: 1}}});
  }

  render() {
    return (
      <Full>
        <CacheRoute path="/book/firstTest/welcome" exta component={Welcome}/>
        <CacheRoute path="/book/firstTest/test" exta component={_ => <TestQuiz type={1}/>}/>
        <CacheRoute path="/book/firstTest/tuijian" exta component={TuiJian}/>
      </Full>
    );
  }
}

FirstTest.propTypes = {};

const opts = ({quiz}) => {
  const {quizList = []} = quiz || {};
  return {
    quizList
  };
};
export default connect(opts)(FirstTest);
